/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cp1300a2;

/**
 *
 * @author apple
 */
public class Main {

    /**
     * pause function
     *
     * credit http://www.rgagnon.com/javadetails/java-0145.html
     * via google
     * @param s
     */
    public static void pause(long s) {
     try {
       Thread.currentThread().sleep(s * 1000);
       }
     catch (InterruptedException e) {
       e.printStackTrace();
       }
    }
    /**
     * main function
     *
     *
     * @param args
     */
    public static void main(String[] args) {

        Menu.start();
        /*
         * debug
         
        Roads.setCycles(1);
        Roads.setH_car(1);
        Roads.setV_car(1);
        Roads.setH_lane(3);
        Roads.setV_lane(3);
        Roads.setCycles(2);
        */
        while (Roads.getCycles() > 0) {


            System.out.print("Starting in:");
            pause(3);
            System.out.print("....3....");
            pause(3);
            System.out.print("....2....");
            pause(3);
            System.out.print("....1....");
            pause(3);
            
            Cars.init();
            Roads.init();
            //System.out.println(Cars.getCars_count());
            while (Cars.traveling() > 0) {
                Roads.run();
                Roads.display();
                pause(1);
            }
            Roads.setCycles(Roads.getCycles() - 1);
        }
        System.exit(0);
    }

}
